<?php


// 获取设备号
function get_device_type(){
    $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
    $type = 'other';
    if(strpos($agent, 'iphone') || strpos($agent, 'ipad') ){
        $type = 'ios';
    }
    if(strpos($agent, 'android')){
        $type = 'android';
    }
    return $type;
}
// 转换IP地址
function zhuanhuanIpAddres($ip){
   header("Content-type: text/html; charset=utf-8");
   $url = "https://api.map.baidu.com/location/ip?ak=ywPxclaARud3wvFiQjG8K7EoIvQoBUQc&ip=".$ip; 
   $res = file_get_contents($url);
   $r = json_decode($res,true);
   return $r['address'];
}

function mysqlinsert($ip,$borwer,$code,$phone_type){
    $host = "10.8.8.49:3306";
	$name = "root";
	$pass = "Gaozhu1122+";
    $db = "esimkj";
	$ut = "utf8mb4";
    $link=mysqli_connect($host,$name,$pass,$db) or die ('mysql error');
    mysqli_select_db($db,$link);
    mysqli_query($link,"SET NAMES utf8mb4");
    $addtime = date('Y-m-d H:i:s');
    $address = zhuanhuanIpAddres($ip);
    $sql = "insert into yao_tongji (ip,borwer,code,addtime,phone_type,address) value ('$ip','$borwer','$code','$addtime','$phone_type','$address')";
    //echo $sql;die;
    mysqli_query($link,$sql);
    mysqli_close($link);
}
 function GetBrowser(){
    if(!empty($_SERVER['HTTP_USER_AGENT']))
    {
     $br = $_SERVER['HTTP_USER_AGENT'];
     if (preg_match('/MSIE/i',$br)){
       $br = 'MSIE';
     }
     elseif (preg_match('/Firefox/i',$br)){
       $br = 'Firefox';
     }elseif (preg_match('/Chrome/i',$br)){
       $br = 'Chrome';
     }elseif (preg_match('/Safari/i',$br)){
       $br = 'Safari';
     }elseif (preg_match('/Opera/i',$br)){
       $br = 'Opera';
     }else {
       $br = 'Other';
     }
       return $br;
     }else{
       return "Other";
         
     }
   }
$ip = $_SERVER['REMOTE_ADDR'];
$borwer = GetBrowser();
$phonetype = get_device_type();
$code = "";

if($_GET['r'] == "4zfj"){ // 张蓉
    $code = "4zfj";
    mysqlinsert($ip,$borwer,$code,$phonetype);
   
    header('Location:https://base.lingtingkj.com/mobile/Index/register?code=4zfj');
}
if($_GET['r'] == "q179vu"){ // 高进沛
    $code = "q179vu";
    mysqlinsert($ip,$borwer,$code,$phonetype);
    header('Location:https://base.lingtingkj.com/mobile/Index/register?code=q179vu');
}
if($_GET['r'] == "9nzu72"){ // 张寒冬
    $code = "9nzu72";
    mysqlinsert($ip,$borwer,$code,$phonetype);
    header('Location:https://base.lingtingkj.com/mobile/Index/register?code=9nzu72');
}
// 买群的1
if($_GET['r'] == "41ktui"){
    $code = "41ktui";
    mysqlinsert($ip,$borwer,$code,$phonetype);
    header("Location:https://base.lingtingkj.com/mobile/Index/register?code=41ktui");
}
// vf3ybi  廖相樊
if($_GET['r'] == "vf3ybi"){
     $code = "vf3ybi";
     mysqlinsert($ip,$borwer,$code,$phonetype);
    header("Location:https://base.lingtingkj.com/mobile/Index/register?code=vf3ybi");
}
// 张蓉买群2
if($_GET['r'] == "9v1e2v"){
    $code = "9v1e2v";
    mysqlinsert($ip,$borwer,$code,$phonetype);
    header("Location:https://base.lingtingkj.com/mobile/Index/register?code=9v1e2v");
}
// 员工2 刘友鹏
if($_GET['r'] == '14nvu6'){
    $code = "14nvu6";
    mysqlinsert($ip,$borwer,$code,$phonetype);
    header("Location:https://base.lingtingkj.com/mobile/Index/register?code=14nvu6");
}
// 员工17683971771
if($_GET['r'] == 'wisnse'){
    $code = "wisnse";
    mysqlinsert($ip,$borwer,$code,$phonetype);
    header("Location:https://base.lingtingkj.com/mobile/Index/register?code=wisnse");
}
// 13044853897
if($_GET['r'] == 'kvo1ld'){
    $code = "kvo1ld";
    mysqlinsert($ip,$borwer,$code,$phonetype);
    header("Location:https://base.lingtingkj.com/mobile/Index/register?code=kvo1ld");
}